<template>
	<view>
		<!-- 		<view class="searchItem">
			<u-search shape="round" :height="searchObj.height" :input-align="searchObj.inputAlign"
				:show-action="searchObj.showAction" placeholder="名称" @search="onSearch" v-model="searchObj.value">
			</u-search>
		</view>
		<view class="topContainer">
			
		</view> -->
		<template v-for="(item,index) in sandboxList">
			<view class="itemContainer" :key="index">
				<view class="parentWrapper">
					<view class="left" @click="getChildList(item)">
						<view class="titleWrapper">
							{{item.name}}
						</view>
						<image v-if="item.hasChild" class="icon"
							:class="{icon_none: !item.isShowMore, icon_more:item.isShowMore}"
							src="../../static/image/icon_more1.png" mode=""></image>
					</view>
					<sendTiktok
						:id="item.shareParam"
						:contentType="'panorama'"
						:title="item.name"
						>				
					</sendTiktok>
					<!-- 					<button  style="border: none;padding: 0;margin: 0;" plain="true" type="default"
						@click.stop=""
					    :data-title="item.name"
						:data-id="item.shareParam" :data-imageurl="item.shareImage||shopInfo.sandBoxImage||shopInfo.shareImage"
						:data-sharepath="'/pages/client/web/index?shareParam='+item.shareParam" 
					    open-type="share">
					    <view class="right">
							<image src="../../static/image/icon_share.png" class="icon"></image>
					        分享
					    </view> 
					</button> -->
				</view>
				<template v-if="item.isShowMore&&item.hasChild">
					<view v-for="(item1,index1) in item.childList" class="childWrapper" :key="index1">
						<view class="left">
							<view class="title">
								{{item1.name}}
							</view>
						</view>
						<sendTiktok
							:id="item1.shareParam"
							:contentType="'panorama'"
							:title="item1.name"
							>				
						</sendTiktok>

						<!-- 						<button  style="border: none;padding: 0;margin: 0;" plain="true" type="default" 
						    :data-title="item1.name"
							:data-id="item1.shareParam"
              :data-imageurl="shopInfo.shareImage"
							:data-sharepath="'/pages/client/web/index?shareParam='+item1.shareParam" 
						    open-type="share">
						    <view class="right">
						        分享
						    </view> 
						</button> -->
					</view>
				</template>

			</view>
		</template>

	</view>
</template>

<script>
	const api = require("@/static/js/api.js")
	const utils = require("@/static/js/utils.js")
	import {
		mapState,
		mapMutations,
		mapActions
	} from 'vuex';

	let that = null
	import sendTiktok from "./sendTiktok.vue"
	export default {
		data() {
			return {
				searchObj: {
					showAction: false,
					inputAlign: "center",
					value: "",
					height: 80,
				},
				sandboxList: [],
			};
		},
		components: {
			sendTiktok
		},
		
		computed: {
			...mapState({
				hasLogin: state => state.userInfo.hasLogin,
				isAuthPhone: state => state.userInfo.isAuthPhone,
				isAuthUserInfo: state => state.userInfo.isAuthUserInfo,
				isSeller: state => state.userInfo.isSeller,
				sellerObj: state => state.userInfo.sellerObj,
				buyerObj: state => state.userInfo.buyerObj,
				shopInfo: state => state.userInfo.shopInfo,
			}),
		},

		created() {
			that = this
			this.parentListMaterial();
		},
		onShow() {

		},
		methods: {
			...mapMutations(['setUserInfo', 'setLoginStatus', 'setUserId', "setOrigin"]),

			//----清空列表


			getChildList(item) {
				console.log("childListMaterial", item)
				if (item.hasChild) {
					if (item.isShowMore) {
						console.log("childListMaterial 0")
						item.isShowMore = false
					} else {
						console.log("childListMaterial 0", item.isShowMore)
						if (item.childList.length == 0) {
							this.childListMaterial(item);
						} else {
							item.isShowMore = true
						}
					}
				}
			},

			parentListMaterial() {
				api.listMaterials({
					param: {
						parentId: "0"
						// limit:5,
						// page: that.cardObj.pageIndex,
						// param: that.searchObj.value
					}
				}).then(res => {
					that.sandboxList.splice(0, this.sandboxList.length)
					for (let i = 0; i < res.data.length; i++) {
						res.data[i].childList = [];
						res.data[i].isShowMore = false;
						that.sandboxList.push(res.data[i])
					}
				})
			},

			childListMaterial(item) {
				if (item && item.id && item.id.length > 0) {

					api.listMaterials({
						param: {
							parentId: item.id
						}
					}).then(res => {
						item.isShowMore = true;
						item.childList.splice(0, item.childList.length)
						for (let i = 0; i < res.data.length; i++) {
							item.childList.push(res.data[i])
						}
					})
				}
			},
		}
	}
</script>
<style>
	page {
		background-color: #ffffff;
	}
</style>

<style lang="scss">
	.searchItem {
		position: fixed;
		top: 0;
		left: 0;
		width: 750rpx;
		background-color: #ffffff;
		padding: 20rpx 30rpx;
	}

	.topContainer {
		height: 120rpx;
	}

	.itemContainer {
		width: 100%;
		background: #FFFFFF;
		box-shadow: 2rpx 2rpx 8rpx 4rpx #EEEEEE;
		border-radius: 20rpx;
		padding: 32rpx 22rpx;
		margin-top: 20rpx;

		.parentWrapper {
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 20rpx 0;

			.left {
				width: 400rpx;
				display: flex;
				align-items: center;

				.titleWrapper {
					max-width: 300rpx;
					margin-right: 30rpx;
					height: 35rpx;
					line-height: 35rpx;
					font-size: 26rpx;
				}

				.icon {
					width: 30rpx;
					height: 30rpx;
					transition-property: all;
					transition-duration: 0.2s;
				}

				.icon_none {
					transform: rotate(-90deg);
				}

				.icon_more {
					transform: rotate(-0deg);
				}
			}


			.right {
				height: 50rpx;
				width: 140rpx;
				border-radius: 30rpx;
				background-color: #007aff;
				color: #ffffff;
				font-size: 22rpx;
				text-align: center;
				line-height: 50rpx;
				display: flex;
				align-items: center;
				justify-content: center;

				.icon {
					width: 30rpx;
					height: 30rpx;
					margin-right: 10rpx;
				}
			}

		}

		.childWrapper {
			width: 80%;
			display: flex;
			align-items: center;
			justify-content: space-between;
			background-color: #ffffff;
			padding: 15rpx 0rpx 15rpx 0;
			margin-left: 20%;

			.left {
				width: 400rpx;
				line-height: 35rpx;
				font-size: 26rpx;
				display: flex;
				align-items: center;

				.title {
					max-width: 350rpx;
					height: 35rpx;
				}

				.icon {
					width: 20rpx;
					height: 20rpx;
				}
			}


			.right {
				height: 50rpx;
				width: 140rpx;
				border-radius: 30rpx;
				background-color: #007aff;
				color: #ffffff;
				font-size: 22rpx;
				text-align: center;
				line-height: 50rpx;
				display: flex;
				align-items: center;
				justify-content: center;

				.icon {
					width: 30rpx;
					height: 30rpx;
					margin-right: 10rpx;
				}
			}

		}
	}
</style>